# myapp/utils/genpass.py
import secrets, pathlib

# 把单词表打包进项目，避免运行时找不到
WORD_FILE = pathlib.Path(__file__).with_name('eff_large_wordlist.txt')
# 没有就自动生成 2048 个简单单词
# if not WORD_FILE.exists():
#     WORD_FILE.write_text('\n'.join(f'word{i:04}' for i in range(2048)), encoding='utf-8')

WORDS = WORD_FILE.read_text().splitlines()

def diceware(words: int = 5, sep: str = '-') -> str:
    """返回人类可记忆的口令，默认 5 个单词"""
    return sep.join(secrets.choice(WORDS) for _ in range(words))